package com.swanclouds.redfish.account.domain.Oem.HuaWei;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.swanclouds.model.common.redfish.Oem;
import com.swanclouds.redfish.common.utils.StringHepler;

import java.util.List;

/**
 * @author 张立强
 * @version jdk1.8.0
 * {
 *     "Huawei":{
 *         "AccountInsecurePromptEnabled":"AccountInsecurePromptEnabled_value",
 *         "FirstLoginPolicy":"FirstLoginPolicy value",
 *         "LoginInterface":[
 *             "LoginInterface_value"
 *         ],
 *         "SnmpV3AuthProtocol":"SnmpV3AuthProtocol",
 *         "SnmpV3PrivProtocol":"SnmpV3PrivProtocol",
 *         "SnmpV3PrivPasswd":"password_value",
 *         "LoginRule":[
 *             "LoginRule_value"
 *         ]
 *     }
 * }
 *  AccountInsecurePromptEnabled: 用户不安全提示状态
 *  FirstLoginPolicy: 账户密码被修改后，首次登陆时的密码修改策略 [ForcePasswordReset,PromptPasswordReset]  iBMC V2 3.2.0.6及以上版本支持
 *  LoginInterface: 用户登录接口 数组类型，取值为["Web","Snmp","IPMI","SSH","SFTP","Local","Redfish"]中的一个或者多个，分别表示用户可支持登录的接口，若为空则都不支持
 *  SnmpV3AuthProtocol: V3鉴权算法[MD5,SHA,SHA1(已废弃,等价于SHA),SHA256,SHA384,SHA512]
 *  SnmpV3PrivProtocol: V3加密算法[DES,AES,AES256]加密算法AES256只能与鉴权算法SHA256、SHA384或SHA512搭配使用
 *  SnmpV3PrivPasswd: 被用于SNMPv3鉴权的用户的加密密码
 *  LoginRule: 用户登录规则 类型为数组，取值为"Rule1"、"Rule2"、"Rule3"中的一个或者多个，分别表示规则一，规则二和规则三
 */
@JsonRootName("Oem")
public class HuaWeiUpdateAccountOem implements Oem {

    @JsonProperty("Huawei")
    private HuaWeiUpdateAccount huawei;

    @JsonRootName("Huawei")
    public static class HuaWeiUpdateAccount {

        @JsonProperty("AccountInsecurePromptEnabled")
        private Boolean insecurePromptEnabled;

        @JsonProperty("FirstLoginPolicy")
        private LoginPolicy firstLoginPolicy;

        @JsonProperty("LoginInterface")
        private List<String> loginInterfaces;

        @JsonProperty("SnmpV3AuthProtocol")
        private V3AuthProtocol snmpV3AuthProtocol;

        @JsonProperty("SnmpV3PrivProtocol")
        private V3PrivProtocol snmpV3PrivProtocol;

        @JsonProperty("SnmpV3PrivPasswd")
        private String snmpV3PrivPasswd;

        @JsonProperty("LoginRule")
        private List<String> loginRules;

        public enum LoginPolicy {
            ForcePasswordReset,PromptPasswordReset;
        }
        public enum V3AuthProtocol {
            MD5,SHA,SHA1,SHA256,SHA384,SHA512;
        }
        public enum V3PrivProtocol {
            DES,AES,AES256;
        }
        private HuaWeiUpdateAccount() {}

        public static HuaWeiUpdateAccount create() {
            return new HuaWeiUpdateAccount();
        }

        public HuaWeiUpdateAccount InsecurePromptEnabled(Boolean insecurePromptEnabled) {
            this.insecurePromptEnabled = insecurePromptEnabled;
            return this;
        }

        public HuaWeiUpdateAccount LoginPolicy(String firstLoginPolicy) {
            this.firstLoginPolicy = LoginPolicy.valueOf(firstLoginPolicy);
            return this;
        }

        public HuaWeiUpdateAccount Interfaces(List<String> loginInterfaces) {
            this.loginInterfaces = loginInterfaces;
            return this;
        }

        public HuaWeiUpdateAccount addLoginInterface(String loginInterface) {
            this.loginRules = Lists.newArrayList();
            if (StringHepler.isNotBlank(loginInterface)) {
                this.loginRules.add(loginInterface);
            }
            return this;
        }

        public HuaWeiUpdateAccount V3AuthProtocol(String snmpV3AuthProtocol) {
            this.snmpV3AuthProtocol = V3AuthProtocol.valueOf(snmpV3AuthProtocol);
            if (this.snmpV3AuthProtocol == null) {
                this.snmpV3AuthProtocol = V3AuthProtocol.MD5;
            }
            return this;
        }

        public HuaWeiUpdateAccount V3PrivProtocol(String snmpV3PrivProtocol) {
            this.snmpV3PrivProtocol = V3PrivProtocol.valueOf(snmpV3PrivProtocol);
            if (this.snmpV3PrivProtocol == null) {
                this.snmpV3PrivProtocol = V3PrivProtocol.DES;
            }
            if ("SHA256".equalsIgnoreCase(this.snmpV3AuthProtocol.name()) ||
                    "SHA384".equalsIgnoreCase(this.snmpV3AuthProtocol.name()) ||
                    "SHA512".equalsIgnoreCase(this.snmpV3AuthProtocol.name())) {
                this.snmpV3PrivProtocol = V3PrivProtocol.AES256;
            }
            return this;
        }

        public HuaWeiUpdateAccount V3PrivPasswd(String snmpV3PrivPasswd) {
            this.snmpV3PrivPasswd = snmpV3PrivPasswd;
            return this;
        }

        public HuaWeiUpdateAccount Rules(List<String> loginRules) {
            this.loginRules = loginRules;
            return this;
        }

        public HuaWeiUpdateAccount addLoginRule(String loginRule) {
            this.loginRules = Lists.newArrayList();
            if (StringHepler.isNotBlank(loginRule)) {
                this.loginRules.add(loginRule);
            }
            return this;
        }

        @Override
        public String toString() {
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                return objectMapper.writeValueAsString(this);
            } catch (JsonProcessingException e) {
            }
            return "HuaWeiUpdateAccount {" +
                    "insecurePromptEnabled=" + insecurePromptEnabled +
                    ", firstLoginPolicy=" + firstLoginPolicy +
                    ", loginInterfaces=" + loginInterfaces +
                    ", snmpV3AuthProtocol=" + snmpV3AuthProtocol +
                    ", snmpV3PrivProtocol=" + snmpV3PrivProtocol +
                    ", snmpV3PrivPasswd='" + snmpV3PrivPasswd + '\'' +
                    ", loginRules=" + loginRules +
                    '}';
        }
    }


    private HuaWeiUpdateAccountOem() {}

    public static HuaWeiUpdateAccountOem create() {
        return new HuaWeiUpdateAccountOem();
    }

    public HuaWeiUpdateAccountOem name(HuaWeiUpdateAccount name) {
        this.huawei = name;
        return this;
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "HuaWeiUpdateAccountOem {" +
                "huawei=" + huawei +
                '}';
    }
}
